<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="Totomo">
  <meta name="Keywords" content="identifying_code">
  <meta name="Description" content="六位验证码">
  <title>六位验证码</title>
  <script type="text/javascript">
	var strc = "";
	function ref(){
	  str="";
	  var li1 = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
	  var li2 = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
	  
	  for (var i=0;i<6;i++){
		var num = Math.floor(Math.random()*61+1);
		if (num<11){
			strc = strc+(num-1);
			str = str + "&nbsp;" + (num-1);
		}else if (num<37){
			num = num - 11;
			strc = strc + li1[num];
			str = str + "&nbsp;" + li1[num];
		}else {
			num = num - 37;
			strc = strc + li2[num];
			str = str + "&nbsp;" + li2[num];
		}
	  }
	  document.getElementById("code").innerHTML=str;
	}
	  
	function icode(){
		var mycode = document.getElementById("identify").value;
		if (mycode==strc){
			alert("验证码正确！");
		}else {
			alert("验证码错误！");
			ref();
		}
	}
  </script>
  </head>
  <body>
	<h4>从小写、大写、数字随机产生6位数验证码</h4>
	<input type="text" style="80px" maxlength="6" id="identify"/>
	<button onclick="icode()">确认</button><span id="code" style="color:orangered"></span>
	<script type="text/javascript">
		ref();
	</script>
  </body>